/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1688888888888_8888';

  // add your middleware config here
  config.middleware = [];

  // 配置公共资源访问
  config.static = {
    prefix: '/public/',
    dir: require('path').join(appInfo.baseDir, 'app/public'),
    maxAge: 31536000,
  };

  // 配置安全设置
  config.security = {
    csrf: {
      enable: false, // 关闭CSRF以便于API测试
    },
  };

  // 配置文件上传
  config.multipart = {
    mode: 'stream', // 改为stream模式
    fileSize: '100mb',    // 最大文件大小
    whitelist: ['.mp4'], // 允许上传的文件扩展名
    fileExtensions: ['.mp4'], // 额外允许的文件扩展名
  };

  // 配置Body解析
  config.bodyParser = {
    jsonLimit: '1mb',
    formLimit: '1mb',
    enableTypes: ['json', 'form'],
    extendTypes: {
      form: ['application/x-www-form-urlencoded'],
      json: ['application/json'],
    },
  };

  config.ffmpeg = {
    ffmpegPath: require('@ffmpeg-installer/ffmpeg').path,
    ffprobePath: require('@ffprobe-installer/ffprobe').path
  };

  // 增加请求超时时间
  config.httpclient = {
    timeout: 120000, // 120秒超时
    request: {
      timeout: 120000, // 30秒超时
    },
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
